﻿from rrDefine import *
from rrMap import *
import rrFunc

#*******************************************************************************
#
#	CURSOR
#
#*******************************************************************************

class Cursor():
	def __init__(self, player):
		self.x=player.x
		self.y=player.y
		self.color=COLOR_WHITE

	def draw_cursor(self):
		init_pair(self.color,COLOR_BLACK,self.color);
		mvaddstr(self.y,self.x,' ',COLOR_PAIR(self.color));
		
	def move_cursor(self, player, objects, map):
		c=getch()
		dx=0
		dy=0
		if c==KEY_RIGHT:
			dx=1
			dy=0
		elif c==KEY_LEFT:
			dx=-1
			dy=0
		elif c==KEY_UP:
			dx=0
			dy=-1
		elif c==KEY_DOWN:
			dx=0
			dy=1
		
		if (self.x+dx>=0 and self.x+dx<MAP_W) and (self.y+dy>=0 and self.y+dy<MAP_H):
			self.x+=dx
			self.y+=dy
			
		rrFunc.blit_screen(player, objects, map)
		mvaddstr(0,0,'select an object by pressing \';\' again')
		self.draw_cursor()
		return c
		
	def get_info(self, player, objects, map):
		rrFunc.blit_screen(player, objects, map)
		mvaddstr(0,0,'select an object by pressing \';\' again');
		c=None
		while c!=59:
			c=self.move_cursor(player, objects, map)
			
		#TODO
		rrFunc.blit_screen(player, objects, map)
		mvaddstr(0,0,str(map[self.x][self.y].sprite));
		return rrFunc.handle_key(player, objects, map)
		
	def target(self, player):
		return rrFunc.handle_key(player, objects, map)